<template>
  <div class="allMembers">
    <div class="search">
      <div>
        <label>搜索：</label>
      </div>

      <el-input v-model="listParams.keyword" placeholder="ID/昵称"></el-input>
      <div>
        <el-button @click='searchKeyWord' type="primary">搜索</el-button>
      </div>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="id" width="90">
        <template slot-scope="scope">
          <span @click="userDetails(scope.row)" class="link-type">{{scope.row.id}}</span>
        </template>
      </el-table-column>
      <el-table-column label="头像" width="90">
        <template slot-scope="scope">
          <div class="imgBox">
            <img :src="scope.row.avatar" alt>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="code" label="推荐码"></el-table-column>
      <el-table-column prop="name" label="发行商名称"></el-table-column>
      <el-table-column label="注册手机号">
        <template slot-scope="scope">
          <!-- {{ scope.row.time | parseTime('{y}-{m}-{d} {h}:{i}') }} -->
          <span>{{scope.row.mobile}}</span>
        </template>
      </el-table-column>
      <el-table-column label="推荐人">
        <template slot-scope="scope">
          <span class="link-type">{{getInviteUser(scope.row.inviteUserId)}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="totalProject" label="项目数量"></el-table-column>
      <el-table-column label="添加时间">
        <template slot-scope="scope">
          <!-- {{ scope.row.time | parseTime('{y}-{m}-{d} {h}:{i}') }} -->
          <span>{{ scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pagination"
      background
      @current-change="handleCurrentChange"
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>

    <!-- 余额明细 -->
    <billDetails ref="billDetails"></billDetails>
  </div>
</template>


<script>
import {ajax} from '@/api';
import { parseTime } from '@/utils'
import {getToken} from "@/utils/auth";
import { cityData } from "@/api/cityData.js";
import billDetails from "./components/billDetails";
export default {
  name: "publisher",
  data() {
    return {
      addMarketDialogVisible:false,
      input: "",
      cityCurrent:[],
      cityData:cityData,
      genderList:[{
        label:'男',
        value:'male'
      },{
        label:'女',
        value:'female'
      }],
      tableData: [],
      total:0,
      listParams:{
        role:'issue',
        auth:0,
        keyword:'',
        start:0,
        limit:10,
        token:getToken()
      },
      userList:[]
    };
  },
  methods: {
    searchKeyWord(){
      if(this.listParams.keyword === ''){
        return this.$message.error('ID/昵称不能为空');
      }
      this.getList();
    },
    getInviteUser(number){
      console.log(this.userList[number]);
      if(this.userList[number]){
        if(this.userList[number].name){
          return this.userList[number].name;
        }else{
          return '--';
        }
      }else{
        return '--';
      }
      
      
    },
    handleChange(value) {
      this.form.areaId = value[value.length-1];
      console.log(this.form);
    },
    handleCurrentChange(val){
        this.listParams.start = (val - 1) * this.listParams.limit;
        this.getList();
    },
    //发行商列表
    getList(){
      ajax('users',this.listParams).then((res) => {
        if(res.status === 200){
          this.total = res.data.total;
          this.tableData = res.data.data;
          this.userList = res.data.users;
        }else{
          this.$message.error(json.message);
        }
      });
    },
    //验证
    vails(){
      if(this.form.name === ''){
        return this.$message.error('请输入发行商名称');
      }

      if(this.form.name === ''){
        return this.$message.error('请选择性别');
      }

      if(this.cityCurrent.length === 0){
        return this.$message.error('请输入发行商地址');
      }

      if(this.form.inviteUserId === ''){
        return this.$message.error('请输入邀请人的ID');
      }
      
      if(this.form.mobile === ''){
        return this.$message.error('请输入发行商联系电话');
      }
      if(this.form.password === ''){
        return this.$message.error('请输入发行商登录密码');
      }
    },

    //验证是否是正确手机号
    isPoneAvailable(number){
      let myReg = /^[1][3,4,5,7,8][0-9]{9}$/;
      if (!myreg.test(number)) {
          return this.$message.error('请输入正确格式的手机号');
      } else {
          return;
      }

    },
    
    
    openbillDetails() {
      this.$refs.billDetails.openBill();
    },
    userDetails(data) {
      this.$router.push({ name: "publisherDetails",params:{id:data.id}});
    }
  },
  mounted(){
    this.getList();
  },
  components: {
    billDetails
  }
};
</script>


<style lang="less" scoped>
.allMembers {
  padding: 1rem;
  .search {
    display: flex;
    margin: 0.5rem 0 1rem 0;
    div:first-child {
      width: 3.5rem;
      line-height: 2.5rem;
      label {
        font-weight: 400;
      }
    }
    div:nth-child(2) {
      width: 11rem;
      margin-right: 1rem;
    }
    div:nth-child(3){
        margin-right: 1rem;
    }
  }
  .imgBox {
    width: 50px;
    height: 50px;
    margin: 0 auto;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50px;
    }
  }
  .pagination{
    text-align: right;
    margin: 1rem 0;
  }
  .select{
    width: 100%;
  }
}
</style>
